//
//  WaitingRepairTableViewCell3.m
//  GetPowerDBO
//
//  Created by 周博 on 2017/8/2.
//  Copyright © 2017年 BogoZhou. All rights reserved.
//

#import "WaitingRepairTableViewCell3.h"
#import "RepairDetailV2ViewController.h"

@interface WaitingRepairTableViewCell3 ()
{
    CGFloat _cellHeight;
}
@end

@implementation WaitingRepairTableViewCell3

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    UITapGestureRecognizer *tapRecognizerTel=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(callFun)];
    
    _labelMerTel.userInteractionEnabled=YES;
    [_labelMerTel addGestureRecognizer:tapRecognizerTel];
    
    
    UITapGestureRecognizer *tapRecognizerDetail=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(seeDetailFunc)];
    
    _labelMan3Hours.userInteractionEnabled=YES;
    [_labelMan3Hours addGestureRecognizer:tapRecognizerDetail];
    
    
    _imageViewHeader.layer.masksToBounds = YES;
    _imageViewHeader.layer.cornerRadius = 10;
}

- (void)showDataWithModel:(WaitingRepairModel *)model{
    _cellHeight = 135;
    _ids = model.charging_info_ids;
    _dateString = model.date;
    _status = model.status;
    model.shop = [[ShopModel alloc] init];
    [model.shop setValuesForKeysWithDictionary:model.store_info];
    
    [_imageViewHeader sd_setImageWithURL:[NSURL URLWithString:model.shop.img_url] placeholderImage:[UIImage imageNamed:@""]];
    
    _labelShopName.text = model.shop.name;
    
    _labelMerName.text = model.shop.contact;
    
    _labelMerTel.text = model.shop.tel;
    _labelAddress.text = [NSString stringWithFormat:@"%@%@",model.shop.area_name,model.shop.specific_address];

    
    //已铺
    _labelAllNum.text = [NSString stringWithFormat:@"%ld",model.already_num.integerValue + model.mima_already_num.integerValue];
    
    //状态
    _labelWatingRepair.text = [NSString stringWithFormat:@"%@",model.status.integerValue == 0 ? @"待维护" : @"维护成功"];
    
    

    if (model.already_num.integerValue == 0) {
        _layoutWifiHeight.constant = 0;
    }else{
        _cellHeight += 60;
        _labelWifiYiPu.text = [NSString stringWithFormat:@"已铺：%@",model.already_num];
        //合格
        if (model.status.integerValue == 0) {//待维护
            _labelMan3Hours.text = [NSString stringWithFormat:@"昨日满2小时：%@",model.ok_num];
        }else{
            _labelMan3Hours.text = [NSString stringWithFormat:@"今日满2小时：%@",model.already_num];
        }
        _labelWifiShishiZaixian.text = [NSString stringWithFormat:@"实时在线：%@",model.online_num];
        _labelWifiShishiLiXian.text = [NSString stringWithFormat:@"实时离线：%@",model.offline_num];
        _labelWifiPingJunZaiXian.text = [NSString stringWithFormat:@"平均在线：%@",model.avg_online_num];
    }
    
    if (model.mima_already_num.integerValue == 0) {
        _layoutMimaHeight.constant = 0;
        _imageViewUnderLine.hidden = YES;
    }else{
        _imageViewUnderLine.hidden = NO;
        _cellHeight += 40;
        _labelMimaYiPu.text = [NSString stringWithFormat:@"已铺：%@",model.mima_already_num];
        
        _labelMimaShiyong.text = [NSString stringWithFormat:@"使用：%@",model.mima_ok_num];
    }
}

- (CGFloat)height{
    return _cellHeight;
}

- (UIViewController *)viewController {
    UIResponder *next = self.nextResponder;
    do {
        //判断响应者是否为视图控制器
        if ([next isKindOfClass:[UIViewController class]]) {
            return (UIViewController *)next;
        }
        next = next.nextResponder;
    } while (next != nil);
    
    return nil;
}

- (void)callFun{
    
    NSMutableString *str=[[NSMutableString alloc] initWithFormat:@"tel:%@",_labelMerTel.text];
    UIWebView *callWebview = [[UIWebView alloc] init];
    [callWebview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:str]]];
    [[self viewController].view addSubview:callWebview];
}

- (void)seeDetailFunc{
    //点击查看详情
    //    kAlert(@"点击查看详情");
    UIStoryboard *storyboard = kMainStroyboard;
    RepairDetailV2ViewController *VC = [storyboard instantiateViewControllerWithIdentifier:@"RepairDetailV2ViewController"];
    VC.dateString = _dateString;
    VC.ids = _ids;
    VC.status = _status;
    VC.modalPresentationStyle = UIModalPresentationOverFullScreen;
    [[self viewController] presentViewController:VC animated:NO completion:nil];
}

- (void)prepareForReuse{
    [super prepareForReuse];
    [self updateConstraints];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
